Resolving package versions...
No Changes to `/workspaces/Kalman filtering and smoothing/Project.toml`
No Changes to `/workspaces/Kalman filtering and smoothing/Manifest.toml`
Pkg.status()
Status `/workspaces/Kalman filtering and smoothing/Project.toml`
[6e4b80f9] BenchmarkTools v1.8.0
[31c24e10] Distributions v0.25.131
[b964fa9f] LaTeXStrings v1.4.1
[91a5bcdd] Plots v1.41.7
⌅ [86711068] RxInfer v3.10.1
[860ef19b] StableRNGs v1.0.4
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`
Kalman filtering and smoothing (Part 3)
This is an analysis of the RxInfer example at https://examples.rxinfer.com/categories/basic_examples/kalman_filtering_and_smoothing/
Some symbols have been changed
Some content has been added/modified
The preference is to make the math and code names align as much as possible
have a boldface e.g. \(\mathbf{x}\) or \(\boldsymbol{x}\) or \(\mathbf{A}\) or \(\mathbf{\mathbb{X}}\)
code
have a underscore prefix e.g. _x or _A or _𝕏
small case / cap case / blackboard case are generally used to discriminate between vectors, matrices, and cuboids
start of alphabet / end of alphabet are generally used to discriminate between ‘system’ and ‘signal’
Time structure identifiers (i.e. time sequence/series)
math
have a colon subscript e.g. \(x_:\) or \(x_{0:n}\) or \(x_{:n}\)
code
have a ː (length mark) suffix e.g. xː
External (i.e. true, environment) states and parameters identifiers
math
have a superscript * e.g. \(v^*\)
code
have a superscript x e.g. vˣ
the ‘x’ in the code superscript is used to imitate the * superscript in the math
In the following set of examples the goal is to estimate hidden states of a Dynamical process where all hidden states are Gaussians.
We start our journey with a simple
multivariate Linear Gaussian State Space Model (LGSSM), which can be solved analytically. We then solve an
identification problem which does not have an analytical solution. Utimately, we show how RxInfer.jl can
deal with missing observations.
3 Handling Missing Data
An interesting case in filtering and smoothing problems is the processing of missing data. It can happen that sometimes your reading devices fail to acquire the data leading to missing observation.
Let us assume that the following model generates the data
\[\begin{aligned}
{x}_t &\sim \mathcal{N}\left({x}_{t-1}, w\right) \\
{y}_t &\sim \mathcal{N}\left({x}_{t}, v \right)
\end{aligned}\] where \(w = 1.0\)
with prior \({x}_0 \sim \mathcal{N}({m_{{x}_0}}, {v_{{x}_0}})\). Suppose that our measurement device fails to acquire data from time to time. In this case, instead of scalar observation \(y_t \in \mathcal{R}\) we sometimes will catch missing observations.
## Data comes from either a simulation/lab (sim|lab) OR from the field (fld)## Data are handled either in batches (batch) OR online as individual points (point)## Batch data accumulates either## along the depth/examples dimension/axis (into the screen/page), OR## typical for supervised & unsupervised learning## along the time dimension/axis (down the screen page)## typical for sequential decision learning (reinforcement learning & active inference)functionsim_batch_data(T; seed=123, μᵥᵥ, σ²ᵥᵥ, μᵥ, σ²ᵥ) ## simulated batch data rng =StableRNG(seed) fEː =fE(T=T) wː =rand(Normal(μᵥᵥ, sqrt(σ²ᵥᵥ)), T) xˣː = fEː + wː gEː =gE(xˣː) vː=rand(Normal(μᵥ, sqrt(σ²ᵥ)), T) yː = gEː + vː y_missingː =similar(yː, Union{Float64, Missing}, )copyto!(y_missingː, yː)for index in missing_indices y_missingː[index] =missingendreturn fEː, xˣː, gEː, yː, y_missingːend